#pragma once

#include <QString>
#include <QVector>
#include <QHash>
#include <QVariant>

namespace infrastructure {

/**
 * @brief 配置验证错误
 */
struct ValidationError {
    QString key;        // 错误的配置键
    QString message;    // 错误消息
    QString severity;   // 严重级别: "error", "warning", "info"
};

/**
 * @brief 配置验证结果
 */
struct ValidationResult {
    bool isValid;
    QVector<ValidationError> errors;
    
    ValidationResult(bool valid = true) : isValid(valid) {}
    
    void addError(const QString& key, const QString& message, const QString& severity = "error") {
        errors.append({key, message, severity});
        if (severity == "error") {
            isValid = false;
        }
    }
    
    bool hasErrors() const {
        return !errors.isEmpty();
    }
    
    bool hasErrorsOfSeverity(const QString& severity) const {
        for (const auto& error : errors) {
            if (error.severity == severity) {
                return true;
            }
        }
        return false;
    }
};

/**
 * @class IConfigurationValidator
 * @brief 配置验证器接口
 */
class IConfigurationValidator {
public:
    virtual ~IConfigurationValidator() = default;

    /**
     * @brief 验证配置数据
     * @param configData 要验证的配置数据
     * @return ValidationResult 验证结果
     */
    virtual ValidationResult validate(const QHash<QString, QVariant>& configData) = 0;

    /**
     * @brief 获取验证器的名称
     * @return QString 验证器名称
     */
    virtual QString getName() const = 0;

    /**
     * @brief 获取验证器的描述
     * @return QString 验证器描述
     */
    virtual QString getDescription() const = 0;
};

} // namespace infrastructure 